﻿using PLC.Application.Devices.Services;
using PLC.Interface.Devices;
using System.Threading.Tasks;
using YWM;
using YWM.Dto;

namespace PLC.Application.Devices
{
    public class DeviceAppService : IDeviceAppService
    {
        private readonly IDeviceService _deviceService = YApp.Resolve<IDeviceService>();

        public async Task<DeviceDto> Get()
        {
            PagedResultDto<DeviceDto> pagedResultDto = await _deviceService.GetAll(new PagedResultRequestDto { MaxResultCount = 1 });
            return pagedResultDto.TotalCount == 0 ? new DeviceDto() : pagedResultDto.Items[0];
        }

        public Task<DeviceDto> Save(DeviceDto input)
        {
            return input.Id > 0 ? _deviceService.Update(input) : _deviceService.Create(input);
        }
    }
}
